From a9e978346b427427e5a30ac2ec657803f9fc93ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:28:02 +0000 Subject: [PATCH 01/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e6db24e..7f1afda 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/ndarray-base-slice": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 018a9af3bff3931c2a43dabad20c43d51b4679fc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:30:14 +0000 Subject: [PATCH 02/67] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 73 +- benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 152 - package.json | 74 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 42 files changed, 6218 insertions(+), 7189 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b524804..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: '40 4 * * 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -360,7 +353,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -420,11 +413,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/main/LICENSE -[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 50a22d9..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d960161..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 5469146..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index eefe091..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var g=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var m=g(function(P,v){"use strict";var h=require("@stdlib/assert-is-ndarray-like"),f=require("@stdlib/assert-is-multi-slice"),p=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),w=require("@stdlib/assert-is-boolean").isPrimitive,y=require("@stdlib/assert-has-own-property"),c=require("@stdlib/slice-multi"),q=require("@stdlib/ndarray-base-slice"),b=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function S(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!h(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],y(n,"strict")){if(!w(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=b(a),i===1&&u.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.",u.join(","),0))}if(f(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(p(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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 = MultiSlice.apply( null, 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACd,EAAeW,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKR,EAAe,UAAWW,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBT,EAAYQ,EAAS,QAAS,EAAI,CACtC,GAAK,CAACT,EAAWS,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKhB,EAAcW,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKZ,EAAmBU,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,EAAIZ,EAAW,MAAO,KAAMU,CAAK,CAClC,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAIb,EAAYU,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAhB,EAAO,QAAUW,IC1FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 a31bc90..3a0fb54 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..09049b5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function l(l,h){var c,p,j,v,f,g,u;if(j={strict:!0},p=arguments.length,!t(l))throw new TypeError(d("invalid argument. First argument must be an ndarray. Value: `%s`.",l));if(r(arguments[p-1])){if(n(c=arguments[p-=1],"strict")){if(!i(c.strict))throw new TypeError(d("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",c.strict));j.strict=c.strict}if(f=a(l),1===p&&f.length>0)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",f.join(","),0))}if(s(h)){if(g=h,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(h)){if(v=h,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(v=[],u=1;u\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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 = MultiSlice.apply( null, 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","MultiSlice","apply","err","String","base"],"mappings":";;w7BAqFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAWC,MAAO,KAAMrB,EAU5B,CATC,MAAQsB,GAET,IAAMnB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAIiB,EAAYpB,EAAMG,GAGtB,CAFC,MAAQmB,GACT,MAAM,IAAId,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 16e230f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,152 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var base = require( '@stdlib/ndarray-base-slice' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; i < nargs; i++ ) { - args.push( arguments[ i ] ); - } - } - try { - S = MultiSlice.apply( null, 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 7f1afda..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,53 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..120eda9 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 1d985559f01726bcd78098838ad548753bd089ae Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:30:49 +0000 Subject: [PATCH 03/67] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a8e0b17..54b556c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.1.0-esm/index.mjs'; ``` #### slice( x, ...s\[, options] ) @@ -245,7 +245,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.1.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 19813b7edfaa6ff695bdfe3ede74c959ba89e10a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 19:30:50 +0000 Subject: [PATCH 04/67] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 54b556c..849cfef 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.1.0-esm/index.mjs'; ``` @@ -245,7 +250,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.1.0-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 30a117b24ac4ed02bc83b10165b069b4888becff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:38:34 +0000 Subject: [PATCH 05/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2dc38da..68667fe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "github:stdlib-js/slice-base-args2multislice#main", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 84264bec0dbd9560fb1ac64e705512b597a6b006 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:41:30 +0000 Subject: [PATCH 06/67] Remove files --- index.d.ts | 1760 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7942 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 3a0fb54..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1760 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:max-file-line-count */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 09049b5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function l(l,h){var c,p,j,v,f,g,u;if(j={strict:!0},p=arguments.length,!t(l))throw new TypeError(d("invalid argument. First argument must be an ndarray. Value: `%s`.",l));if(r(arguments[p-1])){if(n(c=arguments[p-=1],"strict")){if(!i(c.strict))throw new TypeError(d("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",c.strict));j.strict=c.strict}if(f=a(l),1===p&&f.length>0)throw new RangeError(d("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",f.join(","),0))}if(s(h)){if(g=h,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(h)){if(v=h,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(v=[],u=1;u\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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 = MultiSlice.apply( null, 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","MultiSlice","apply","err","String","base"],"mappings":";;w7BAqFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAWC,MAAO,KAAMrB,EAU5B,CATC,MAAQsB,GAET,IAAMnB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAIiB,EAAYpB,EAAMG,GAGtB,CAFC,MAAQmB,GACT,MAAM,IAAId,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 120eda9..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6a0c8bc1659fbebf7fe23c38cb350a281c0f6c48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 20:42:55 +0000 Subject: [PATCH 07/67] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 73 +- benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 42 files changed, 6218 insertions(+), 7191 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b524804..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: '40 4 * * 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -360,7 +353,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -420,11 +413,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/main/LICENSE -[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 50a22d9..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d960161..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 5469146..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 a31bc90..3a0fb54 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..983ac40 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;shCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 68667fe..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "github:stdlib-js/slice-base-args2multislice#main", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3f0741e --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 324cf6a1c22f59f723566a7021fa7a647a78cb16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:27:59 +0000 Subject: [PATCH 08/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdf3515..01612ac 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 062a2efcb6d42517f9e97cae0ab254b516126415 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:33:49 +0000 Subject: [PATCH 09/67] Remove files --- index.d.ts | 1760 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7942 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 3a0fb54..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1760 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:max-file-line-count */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 983ac40..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;shCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3f0741e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f28c7fe6094a1268e7ca2eaf6bd09ffc57913463 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 20 Oct 2023 22:35:08 +0000 Subject: [PATCH 10/67] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 73 +- benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 42 files changed, 6218 insertions(+), 7191 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b524804..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: '40 4 * * 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 corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -360,7 +353,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -420,11 +413,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/main/LICENSE -[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib +[@stdlib/slice/multi]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.call_signatures.js b/benchmark/benchmark.call_signatures.js deleted file mode 100644 index 50a22d9..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d960161..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var baseEmpty = require( '@stdlib/ndarray-base-empty' ); -var empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 5469146..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 0807c8f..44c0f68 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..d5abe9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 01612ac..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.0", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..371f550 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7c2ccb16bcb10c0cf2dd6eb8ef4318cd386e50ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:00:01 +0000 Subject: [PATCH 11/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c74ed1..21a1e70 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 44e070829cb49a3e0d4791447322268efc798cd5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:38:54 +0000 Subject: [PATCH 12/67] Remove files --- index.d.ts | 1754 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7936 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 44c0f68..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:max-file-line-count */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // tslint:disable-line:unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d5abe9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 371f550..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4a1041e79c9ddd26a1dded56f94f77c1b77851e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 14:39:27 +0000 Subject: [PATCH 13/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 79 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 44 files changed, 6221 insertions(+), 7196 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index baecce1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:09:05.299Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a95dcda..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: '40 4 * * 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -369,7 +362,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -429,19 +422,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 5469146..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 f1dc617..6731c22 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3a716f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 21a1e70..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b4f8b40 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From e75cd1878758597d842bea22693e064e5e9a447e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 08:32:05 +0000 Subject: [PATCH 14/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4c74ed1..21a1e70 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 39a0443f2aad29d12718a2d2f5e1ba740f225fe4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:58:17 +0000 Subject: [PATCH 15/67] Remove files --- index.d.ts | 1754 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7936 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 6731c22..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var typedarray = require( `@stdlib/array/typed` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( `@stdlib/slice/ctor` ); -* var MultiSlice = require( `@stdlib/slice/multi` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a716f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b4f8b40..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f2b41ce31514277a40798f447fe235559d5926e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 13:58:57 +0000 Subject: [PATCH 16/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 81 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 44 files changed, 6221 insertions(+), 7201 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d0329ee..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T05:58:45.568Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index a95dcda..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: '40 4 * * 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 corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -371,7 +362,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -434,19 +425,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3a716f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 21a1e70..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4350353 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 255f2947a8453e7192a65b034b71df8b8c2a1c27 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 02:42:34 +0000 Subject: [PATCH 17/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77f8444..34734f0 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/slice-base-args2multislice": "^0.1.0", "@stdlib/slice-multi": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 69b6198f77b1f14298f4f1d14d1da4d7ecf4eed5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 02:43:07 +0000 Subject: [PATCH 18/67] Remove files --- index.d.ts | 1754 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7936 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a716f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4350353..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2f203d24fb04afb7c4a647b4f484987a50a39a32 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 02:43:57 +0000 Subject: [PATCH 19/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 43 files changed, 6222 insertions(+), 7205 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 b7e235f..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: '40 4 * * 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3a716f8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 34734f0..5080ad0 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-multi-slice": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/ndarray-base-slice": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/slice-base-args2multislice": "^0.1.0", - "@stdlib/slice-multi": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.1.1", - "@stdlib/ndarray-base-ctor": "^0.1.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9375700 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From b66e173efe607e15a8e310ed79ec8b37dfa625a9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:11:51 +0000 Subject: [PATCH 20/67] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5da53f1..b495a80 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.2.0", "@stdlib/slice-base-args2multislice": "^0.2.0", "@stdlib/slice-multi": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 9225cfb60d043d45b739da4f30e5be28b4a82345 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:08:39 +0000 Subject: [PATCH 21/67] Remove files --- index.d.ts | 1754 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7936 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3a716f8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9375700..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e2a6a481111581b1fece4706462f4d668612ab9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 03:09:34 +0000 Subject: [PATCH 22/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 75 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 43 files changed, 6222 insertions(+), 7205 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 b7e235f..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: '40 4 * * 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 corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..c64e0a2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7b1217f..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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 ( 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( x ); - if ( nargs === 1 && 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 > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); - } - } else { - args = []; - for ( i = 1; 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, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index b495a80..9b31f97 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Return a read-only view of an input ndarray.", "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,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-multi-slice": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/ndarray-base-slice": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/slice-base-args2multislice": "^0.2.0", - "@stdlib/slice-multi": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.1.0", - "@stdlib/array-typed": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-empty": "^0.1.1", - "@stdlib/ndarray-base-from-scalar": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-empty": "^0.1.0", - "@stdlib/ndarray-to-array": "^0.1.0", - "@stdlib/ndarray-zeros": "^0.1.0", - "@stdlib/slice-ctor": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9698965 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7817d2dd6cb2ba902dc50caa000eaf8cbdc482aa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:51:49 +0000 Subject: [PATCH 23/67] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d0d50f..44f70fc 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.0-esm/index.mjs'; ``` #### slice( x, ...s\[, options] ) @@ -245,7 +245,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.0-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From f75d0de06ceac7f8fa5924b7f5eb06ad29e0108c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:51:49 +0000 Subject: [PATCH 24/67] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44f70fc..dea2871 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.0-esm/index.mjs'; ``` @@ -245,7 +250,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.0-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 7ffed92a027d6837b9e9712ccacdd56ec15fe885 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:06:21 +0000 Subject: [PATCH 25/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 57d44f1..56e29c5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-multi": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 40bfc9072d37bbee0227d29eb5faca3d51c41896 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:36:13 +0000 Subject: [PATCH 26/67] Remove files --- index.d.ts | 1754 -------------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 7936 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c64e0a2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";function h(h,c){var j,p,v,f,g,u,b;if(v={strict:!0},p=arguments.length,!s(h))throw new TypeError(l("invalid argument. First argument must be an ndarray. Value: `%s`.",h));if(i(arguments[p-1])){if(n(j=arguments[p-=1],"strict")){if(!r(j.strict))throw new TypeError(l("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",j.strict));v.strict=j.strict}if(g=a(h),1===p&&g.length>0)throw new RangeError(l("invalid argument. Number of slice dimensions does not match the number of array dimensions. Array shape: (%s). Slice dimensions: %u.",g.join(","),0))}if(t(c)){if(u=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else{if(e(c)){if(f=c,p>2)throw new Error("invalid invocation. Too many arguments.")}else for(f=[],b=1;b\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;6hCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,oEAAqEd,IAEnG,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,+DAAgE,SAAUZ,EAAQO,SAEhHL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,uIAAwIR,EAAGc,KAAM,KAAO,GAEvL,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAO,+CAEZ,CACN,GAAKC,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAO,gDAIlB,IADAjB,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EAUrB,CATC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GAGtB,CAFC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,sGAAuGc,OAAQvB,EAAMG,KAClJ,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9698965..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d14dfbe3a46697159eb7929a3747d9389978381f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:36:38 +0000 Subject: [PATCH 27/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 43 files changed, 4887 insertions(+), 7200 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..960d93a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 56e29c5..1831b33 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only view of an input ndarray.", "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,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-multi-slice": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.0", - "@stdlib/array-typed": "^0.2.0", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-empty": "^0.2.0", - "@stdlib/ndarray-to-array": "^0.2.0", - "@stdlib/ndarray-zeros": "^0.2.0", - "@stdlib/slice-ctor": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..05ef4d5 --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 86ee86d6b7e6553f541e3871cee2e814480e9fb8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:06:26 +0000 Subject: [PATCH 28/67] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 08e5de6..d65ac72 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.1-esm/index.mjs'; ``` #### slice( x, ...s\[, options] ) @@ -245,7 +245,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.1-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From d503c492d4a2dcaaed28c4eafab28114d5a85a53 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:06:26 +0000 Subject: [PATCH 29/67] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d65ac72..84d8d32 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.1-esm/index.mjs'; ``` @@ -245,7 +250,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.1-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 3ba1cbad1bb586d064404967bd78a92fb0ea0bf2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 07:52:28 +0000 Subject: [PATCH 30/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index fc8d1d9..112c2ea 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-multi": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From c3b6f95662428ab5d22e004e2e996d5c0053ec9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:32:15 +0000 Subject: [PATCH 31/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 960d93a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 05ef4d5..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c009f9c7303f9eb99d337dcf6be4a8229b05b235 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:32:41 +0000 Subject: [PATCH 32/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7202 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7e869d8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:41:00.190Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3eefd8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 112c2ea..1831b33 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only view of an input ndarray.", "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,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-multi-slice": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6d1b57e --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 77dd7a9e7a32dfc91b224b2faafde47f5087b43d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:10:27 +0000 Subject: [PATCH 33/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index fc8d1d9..112c2ea 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-multi": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From e5626e4ea6ac5b2eb4e25085a551faa021a8f620 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:30:17 +0000 Subject: [PATCH 34/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3eefd8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6d1b57e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 848905154352d03ad934f622fdb5ced598b244a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:30:40 +0000 Subject: [PATCH 35/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7205 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 088ed95..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T04:59:17.016Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3eefd8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 112c2ea..1831b33 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only view of an input ndarray.", "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,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-multi-slice": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6d1b57e --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From e353e8b2ccb0a258a2f81496ecb1077b0d45c663 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:28:05 +0000 Subject: [PATCH 36/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index fc8d1d9..112c2ea 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/slice-base-args2multislice": "^0.2.1", "@stdlib/slice-multi": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From b1fac7f601a0917a85222a1e820f2530cd318f88 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:48:19 +0000 Subject: [PATCH 37/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3eefd8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6d1b57e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 012110a57d69178e8e166ecc3041289c044b8eb0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 08:48:45 +0000 Subject: [PATCH 38/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 43 files changed, 4887 insertions(+), 7206 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..3eefd8a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 112c2ea..1831b33 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Return a read-only view of an input ndarray.", "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,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-multi-slice": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/ndarray-base-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/slice-base-args2multislice": "^0.2.1", - "@stdlib/slice-multi": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@stdlib/slice-ctor": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6d1b57e --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 7c5e618e70e73a7e8d9805f12a1f12997553b99e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:44:52 +0000 Subject: [PATCH 39/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 101f91b..986359c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 1d3b4bf1e61f3586c96849083f216649bc96e801 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:58:21 +0000 Subject: [PATCH 40/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3eefd8a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-multi-slice@v0.2.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as i}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6d1b57e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8abfb947db39c61a5dcd3bc0f3994aeb9e347fe7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 02:58:38 +0000 Subject: [PATCH 41/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 132 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 43 files changed, 4887 insertions(+), 7346 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..4bd916f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 986359c..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.2.1", - "@stdlib/ndarray-base-from-scalar": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-empty": "^0.2.1", - "@stdlib/ndarray-to-array": "^0.2.1", - "@stdlib/ndarray-zeros": "^0.2.1", - "@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..3450c96 --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 0b2342121529b42adbc45cf362e10f0a45902802 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:06:20 +0000 Subject: [PATCH 42/67] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8bccca0..d6f4b6c 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.2-esm/index.mjs'; ``` #### slice( x, ...s\[, options] ) @@ -245,7 +245,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.2-esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From c7299d3db7e755ba7262d3383876ab1444113272 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:06:21 +0000 Subject: [PATCH 43/67] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6f4b6c..7ab3c3b 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-slice/tags). For example, + ```javascript import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.2-esm/index.mjs'; ``` @@ -245,7 +250,7 @@ import E from 'https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; import ndarray2array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@esm/index.mjs'; import zeroTo from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@esm/index.mjs'; -import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@v0.2.2-esm/index.mjs'; +import slice from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-slice@esm/index.mjs'; // Alias `null` to allow for more compact indexing expressions: var _ = null; From 0ece6ea8bdc5fa29cfe3e44201491f3db6ec9ec1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 07:58:47 +0000 Subject: [PATCH 44/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index a982bb5..aa3d166 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 00674653e5e561955411297abade744a678043f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:53:37 +0000 Subject: [PATCH 45/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 4bd916f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3450c96..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bf6372d41479b3408e3ccc10829df07a27605c88 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 12:53:56 +0000 Subject: [PATCH 46/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 78 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7293 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 6ebbf7c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T05:51:35.754Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index aa3d166..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 6b27936df7cad36a46921746843a5cb2f5e01944 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 08:22:15 +0000 Subject: [PATCH 47/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 3866081..478670c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From aafd01e5f2e5c323b266d253f5aa481d29a59a15 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:50:02 +0000 Subject: [PATCH 48/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 929c4a3c2c53e351131c6568175149a82d708bde Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 12:50:20 +0000 Subject: [PATCH 49/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 132 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7347 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 142fdae..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T06:18:12.700Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index a4ddebc..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 478670c..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 882769d8b82d338944fc8005bc41363b90e8eaf7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:26:56 +0000 Subject: [PATCH 50/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 3866081..478670c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From f2c653bd1568e27a6d32a1497b9b4e6b01c5b935 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:39:13 +0000 Subject: [PATCH 51/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ac18b9dff413bbad03349432669d2d16702fc571 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:39:46 +0000 Subject: [PATCH 52/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 43 files changed, 4887 insertions(+), 7380 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 478670c..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From ba6e2df50d2ee380fab79007a7bf913011dc1748 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 08:39:43 +0000 Subject: [PATCH 53/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 3866081..478670c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 9574fdc434009b6ef03cedbe978aaf52edad4407 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:21:28 +0000 Subject: [PATCH 54/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e6ecbcc8761d751e00fcda22eed46f1edc3b8de2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 13:21:48 +0000 Subject: [PATCH 55/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7381 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 25cfbda..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T06:30:22.585Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 478670c..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 36678246e7b7d6084989545da7ccfdde2b8ea7a3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 08:26:09 +0000 Subject: [PATCH 56/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 3866081..478670c 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From eadb4b3a9c2aec32903cf68585e5d25174a51e82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:41 +0000 Subject: [PATCH 57/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6d007644ffa7a27efe6b93ba673d133ae10202d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 12:27:58 +0000 Subject: [PATCH 58/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ----- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 -- examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 -------- 44 files changed, 4887 insertions(+), 7381 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 182749b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T06:33:32.237Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 478670c..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 77d900a23714f33d7ea58819eaa0f4afe0609fd6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 08:42:54 +0000 Subject: [PATCH 59/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 9a260f7..90f4bfe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From eddc55550f9aeee6551a180fc59879ec394f2797 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:50:48 +0000 Subject: [PATCH 60/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 426379332d2e2f89dc9514d8e1b583aa4889cb00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 12:51:04 +0000 Subject: [PATCH 61/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 45 files changed, 4887 insertions(+), 7486 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 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 4c156a9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T06:43:19.471Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 90f4bfe..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 447ec2d1de1e7cb4e8e7c4f4a04c4bc18ca95932 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:45:19 +0000 Subject: [PATCH 62/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 9a260f7..90f4bfe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 430061e2a6f804526c96efc174ba96fc934594db Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:56:37 +0000 Subject: [PATCH 63/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 979c8bc6e3ded85264c187b60218a788e32fb81b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:56:58 +0000 Subject: [PATCH 64/67] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 45 files changed, 4887 insertions(+), 7486 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2b0a743..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:42:01.429Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 000c3f5..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) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..9d357b9 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 90f4bfe..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); From 872610f56add1043e3605d8dad69fb7023172931 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:28:15 +0000 Subject: [PATCH 65/67] Transform error messages --- lib/main.js | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7b1217f..7194ece 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ var MultiSlice = require( '@stdlib/slice-multi' ); var args2multislice = require( '@stdlib/slice-base-args2multislice' ); var base = require( '@stdlib/ndarray-base-slice' ); var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -98,32 +98,32 @@ function slice( x, s ) { }; nargs = arguments.length; if ( !isndarrayLike( x ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + throw new TypeError( format( '1jV4f', x ) ); } 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 ) ); + throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); } opts.strict = options.strict; } sh = getShape( x ); if ( nargs === 1 && 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 ) ); + throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); } } if ( isMultiSlice( s ) ) { S = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { if ( isArrayLikeObject( s ) ) { args = s; if ( nargs > 2 ) { - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('1jV0m') ); } } else { args = []; @@ -139,7 +139,7 @@ function slice( x, s ) { 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 ] ) ) ); + throw new TypeError( format( '1jVEu', String( args[ i ] ) ) ); } } } diff --git a/package.json b/package.json index 9a260f7..90f4bfe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@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/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 439b987f8395dac0f97563047e60a503d95cae12 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:55:10 +0000 Subject: [PATCH 66/67] Remove files --- index.d.ts | 1754 ------------------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 6601 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 04a9184..0000000 --- a/index.d.ts +++ /dev/null @@ -1,1754 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 max-lines */ - -// TypeScript Version: 4.1 - -/// - -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import { MultiSlice, Slice } from '@stdlib/types/slice'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to enforce strict bounds checking (default: true). - */ - strict?: boolean; -} - -/** -* Slice argument. -*/ -type SliceArgument = Slice | number | null | undefined; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: MultiSlice, options?: Options ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, s: ArrayLike, options?: Options ): float64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float64ndarray, ...slices: Array ): float64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: MultiSlice, options?: Options ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, s: ArrayLike, options?: Options ): float32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -declare function slice( x: float32ndarray, ...slices: Array ): float32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: MultiSlice, options?: Options ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, s: ArrayLike, options?: Options ): int32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int32ndarray, ...slices: Array ): int32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: MultiSlice, options?: Options ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, s: ArrayLike, options?: Options ): int16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int16ndarray, ...slices: Array ): int16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: MultiSlice, options?: Options ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, s: ArrayLike, options?: Options ): int8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: int8ndarray, ...slices: Array ): int8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: MultiSlice, options?: Options ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, s: ArrayLike, options?: Options ): uint32ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint32ndarray, ...slices: Array ): uint32ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: MultiSlice, options?: Options ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, s: ArrayLike, options?: Options ): uint16ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint16ndarray, ...slices: Array ): uint16ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: MultiSlice, options?: Options ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, s: ArrayLike, options?: Options ): uint8ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8ndarray, ...slices: Array ): uint8ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: MultiSlice, options?: Options ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, s: ArrayLike, options?: Options ): uint8cndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - slice argument -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: uint8cndarray, ...slices: Array ): uint8cndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: MultiSlice, options?: Options ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, s: ArrayLike, options?: Options ): complex128ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex128ndarray, ...slices: Array ): complex128ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: MultiSlice, options?: Options ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, s: ArrayLike, options?: Options ): complex64ndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var typedarray = require( '@stdlib/array-typed' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -*/ -declare function slice( x: complex64ndarray, ...slices: Array ): complex64ndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: MultiSlice, options?: Options ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, s: ArrayLike, options?: Options ): genericndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: genericndarray, ...slices: Array ): genericndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - multi-slice object -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* var s = new MultiSlice( s0, s1 ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: MultiSlice, options?: Options ): typedndarray; - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param s - array of slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, [ s0, s1 ] ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, s: ArrayLike, options?: Options ): typedndarray; // eslint-disable-line @typescript-eslint/unified-signatures - -/** -* Returns a read-only view of an input ndarray. -* -* @param x - input array -* @param slices - slice arguments -* @param options - function options -* @param options.strict - boolean indicating whether to enforce strict bounds checking -* @returns output array -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* -* var buffer = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var s0 = new Slice( null, null, -2 ); -* var s1 = new Slice( null, null, -1 ); -* -* var y = slice( x, s0, s1 ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 2, 1 ] ] -*/ -declare function slice( x: typedndarray, ...slices: Array ): typedndarray; - - -// EXPORTS // - -export = slice; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9d357b9..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import s from"https://cdn.jsdelivr.net/gh/stdlib-js/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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ebddcdd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5bb03be598ea3e2e74ae8808d4ea866cc1eb6343 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Mar 2025 01:55:46 +0000 Subject: [PATCH 67/67] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 166 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 83 +- SECURITY.md | 5 - benchmark/benchmark.call_signatures.js | 117 - benchmark/benchmark.js | 1113 ---- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 62 - docs/types/test.ts | 252 - examples/index.js | 108 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 67 - lib/main.js | 153 - package.json | 76 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 1923 ------- 45 files changed, 4887 insertions(+), 7489 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.call_signatures.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6699f3a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-17T01:19:38.089Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 328bf73..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) 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 9ae6fe1..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) 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 92d08af..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: '40 4 * * 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 + + ```
@@ -372,7 +363,7 @@ var a8 = ndarray2array( y8 ); ## 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]. @@ -435,21 +426,21 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-slice/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/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/at]: https://github.com/stdlib-js/ndarray-at +[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray-at/tree/esm -[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign +[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray-slice-assign/tree/esm -[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension +[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray-slice-dimension/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 ad5538d..0000000 --- a/benchmark/benchmark.call_signatures.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::2d,base,multislice', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 v; - var i; - - 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 = slice( 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 d532ff3..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1113 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 empty = require( '@stdlib/ndarray-empty' ); -var pkg = require( './../package.json' ).name; -var slice = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::0d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - values = [ - baseEmpty( 'float64', [], 'row-major' ), - baseEmpty( 'float32', [], 'row-major' ), - baseEmpty( 'int32', [], 'row-major' ), - baseEmpty( 'complex128', [], 'row-major' ), - baseEmpty( 'generic', [], 'row-major' ) - ]; - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::0d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* eslint-disable object-curly-newline */ - - values = [ - empty( [], { 'dtype': 'float64' } ), - empty( [], { 'dtype': 'float32' } ), - empty( [], { 'dtype': 'int32' } ), - empty( [], { 'dtype': 'complex128' } ), - empty( [], { 'dtype': 'generic' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice(); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::1d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( new Slice( 10, 20, 1 ) ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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 = slice( 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,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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( new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::3d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::4d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( null, null, null, null, null ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,non-base,reduced', function benchmark( b ) { - var values; - var v; - var s; - var i; - - /* 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' } ) - ]; - - /* eslint-enable object-curly-newline */ - - s = new MultiSlice( 0, 1, 0, 1, 0 ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( 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+'::5d,base,out-of-bounds', function benchmark( b ) { - var values; - var opts; - var v; - var s; - var i; - - 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' ) - ]; - s = new MultiSlice( null, null, null, new Slice( 10, 20, 1 ), null ); - opts = { - 'strict': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = slice( values[ i%values.length ], 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 s; - var i; - - /* 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' } ) - ]; - - /* 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++ ) { - v = slice( values[ i%values.length ], 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 0173cbe..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" -%% click B href "https://github.com/stdlib-js/ndarray-slice/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-slice/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-slice/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-slice/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-slice/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/slice -[production-url]: https://github.com/stdlib-js/ndarray-slice/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-slice/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-slice/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-slice/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-slice/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-slice/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-slice/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 ad3c25f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import slice from '../docs/types/index'; -export = slice; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7b5276a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var v=m(function(k,c){"use strict";var g=require("@stdlib/assert-is-ndarray-like"),h=require("@stdlib/assert-is-multi-slice"),f=require("@stdlib/assert-is-array-like-object"),d=require("@stdlib/assert-is-plain-object"),p=require("@stdlib/assert-is-boolean").isPrimitive,w=require("@stdlib/assert-has-own-property"),q=require("@stdlib/slice-multi"),y=require("@stdlib/slice-base-args2multislice"),b=require("@stdlib/ndarray-base-slice"),S=require("@stdlib/ndarray-shape"),s=require("@stdlib/string-format");function E(a,r){var n,i,o,t,u,l,e;if(o={strict:!0},i=arguments.length,!g(a))throw new TypeError(s("invalid argument. First argument must be an ndarray. Value: `%s`.",a));if(d(arguments[i-1])){if(i-=1,n=arguments[i],w(n,"strict")){if(!p(n.strict))throw new TypeError(s("invalid option. `%s` option must be a boolean. Option: `%s`.","strict",n.strict));o.strict=n.strict}if(u=S(a),i===1&&u.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.",u.join(","),0))}if(h(r)){if(l=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else{if(f(r)){if(t=r,i>2)throw new Error("invalid invocation. Too many arguments.")}else for(t=[],e=1;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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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 ( 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( x );\n\t\tif ( nargs === 1 && 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 > 2 ) {\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 > 2 ) {\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 = 1; 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, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nmodule.exports = slice;\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* Return a read-only view of an input ndarray.\n*\n* @module @stdlib/ndarray-slice\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 ndarray2array = require( '@stdlib/ndarray-to-array' );\n* var slice = require( '@stdlib/ndarray-slice' );\n*\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.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,iCAAkC,EACxDC,EAAa,QAAS,qBAAsB,EAC5CC,EAAkB,QAAS,oCAAqC,EAChEC,EAAO,QAAS,4BAA6B,EAC7CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAS,QAAS,uBAAwB,EAsD9C,SAASC,EAAOC,EAAGC,EAAI,CACtB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACN,OAAU,EACX,EACAD,EAAQ,UAAU,OACb,CAACf,EAAeY,CAAE,EACtB,MAAM,IAAI,UAAWF,EAAQ,oEAAqEE,CAAE,CAAE,EAEvG,GAAKT,EAAe,UAAWY,EAAM,CAAE,CAAE,EAAI,CAG5C,GAFAA,GAAS,EACTD,EAAU,UAAWC,CAAM,EACtBV,EAAYS,EAAS,QAAS,EAAI,CACtC,GAAK,CAACV,EAAWU,EAAQ,MAAO,EAC/B,MAAM,IAAI,UAAWJ,EAAQ,+DAAgE,SAAUI,EAAQ,MAAO,CAAE,EAEzHE,EAAK,OAASF,EAAQ,MACvB,CAEA,GADAI,EAAKT,EAAUG,CAAE,EACZG,IAAU,GAAKG,EAAG,OAAS,EAC/B,MAAM,IAAI,WAAYR,EAAQ,uIAAwIQ,EAAG,KAAM,GAAI,EAAG,CAAE,CAAE,CAE5L,CACA,GAAKjB,EAAcY,CAAE,GAEpB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAI,MAAO,yCAA0C,MAEtD,CACN,GAAKb,EAAmBW,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,EAAIZ,EAAiBU,CAAK,CAC3B,OAAUI,EAAM,CAEf,IAAMD,EAAI,EAAGA,EAAIH,EAAK,OAAQG,IAC7B,GAAI,CACH,IAAId,EAAYW,EAAMG,CAAE,CAAE,CAC3B,OAAUC,EAAM,CACf,MAAM,IAAI,UAAWX,EAAQ,sGAAuG,OAAQO,EAAMG,CAAE,CAAE,CAAE,CAAE,CAC3J,CAEF,CACD,CACA,OAAOZ,EAAMI,EAAGO,EAAGH,EAAK,OAAQ,EAAM,CACvC,CAKAjB,EAAO,QAAUY,IC3FjB,IAAIW,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isndarrayLike", "isMultiSlice", "isArrayLikeObject", "isPlainObject", "isBoolean", "hasOwnProp", "MultiSlice", "args2multislice", "base", "getShape", "format", "slice", "x", "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 416804e..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( x, ...s[, options] ) - Returns a read-only view of an input ndarray. - - 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 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. - - 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 view. - - Examples - -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) - - > x.shape - [ 2, 2 ] - > var s = new {{alias:@stdlib/slice/multi}}( null, 1 ) - - > var y = {{alias}}( x, s ) - - > y.shape - [ 2 ] - > {{alias:@stdlib/ndarray/to-array}}( y ) - [ 2, 4 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index c4ab6b5..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,252 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 MultiSlice = require( '@stdlib/slice-multi' ); -import slice = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const order = 'row-major'; - const sh = [ 2, 2 ]; - const s = new MultiSlice( null, null ); - - slice( empty( 'float64', sh, order ), s ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ] ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ] ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ] ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ] ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ] ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ] ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ] ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ] ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ] ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ] ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ] ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': false } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': false } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': false } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': false } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': false } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': false } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': false } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), s, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), s, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), s, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), s, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), s, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), s, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), s, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), s, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), s, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), s, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), s, { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), [ null, null ], { 'strict': true } ); // $ExpectType uint8cndarray - - slice( empty( 'float64', sh, order ), null, null, { 'strict': true } ); // $ExpectType float64ndarray - slice( empty( 'float32', sh, order ), null, null, { 'strict': true } ); // $ExpectType float32ndarray - slice( empty( 'complex128', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex128ndarray - slice( empty( 'complex64', sh, order ), null, null, { 'strict': true } ); // $ExpectType complex64ndarray - slice( empty( 'int32', sh, order ), null, null, { 'strict': true } ); // $ExpectType int32ndarray - slice( empty( 'int16', sh, order ), null, null, { 'strict': true } ); // $ExpectType int16ndarray - slice( empty( 'int8', sh, order ), null, null, { 'strict': true } ); // $ExpectType int8ndarray - slice( empty( 'uint32', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint32ndarray - slice( empty( 'uint16', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint16ndarray - slice( empty( 'uint8', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8ndarray - slice( empty( 'uint8c', sh, order ), null, null, { 'strict': true } ); // $ExpectType uint8cndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray... -{ - const s = new MultiSlice( null, null ); - - slice( '10', s ); // $ExpectError - slice( 10, s ); // $ExpectError - slice( false, s ); // $ExpectError - slice( true, s ); // $ExpectError - slice( null, s ); // $ExpectError - slice( [], s ); // $ExpectError - slice( {}, s ); // $ExpectError - slice( ( x: number ): number => x, s ); // $ExpectError - - slice( '10', s, {} ); // $ExpectError - slice( 10, s, {} ); // $ExpectError - slice( false, s, {} ); // $ExpectError - slice( true, s, {} ); // $ExpectError - slice( null, s, {} ); // $ExpectError - slice( [], s, {} ); // $ExpectError - slice( {}, s, {} ); // $ExpectError - slice( ( x: number ): number => x, s, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a valid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, '5' ); // $ExpectError - slice( x, true ); // $ExpectError - slice( x, [ '5' ] ); // $ExpectError - slice( x, ( x: number ): number => x ); // $ExpectError - - slice( x, '5', {} ); // $ExpectError - slice( x, false, {} ); // $ExpectError - slice( x, true, {} ); // $ExpectError - slice( x, [ '5' ], {} ); // $ExpectError - slice( x, ( x: number ): number => x, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid slice argument... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - slice( x, null, '5' ); // $ExpectError - slice( x, null, true ); // $ExpectError - slice( x, null, [ '5' ] ); // $ExpectError - slice( x, null, ( x: number ): number => x ); // $ExpectError - - slice( x, null, '5', {} ); // $ExpectError - slice( x, null, false, {} ); // $ExpectError - slice( x, null, true, {} ); // $ExpectError - slice( x, null, [ '5' ], {} ); // $ExpectError - slice( x, null, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, '5' ); // $ExpectError - slice( x, null, 1, true ); // $ExpectError - slice( x, null, 1, [ '5' ] ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, '5', {} ); // $ExpectError - slice( x, null, 1, false, {} ); // $ExpectError - slice( x, null, 1, true, {} ); // $ExpectError - slice( x, null, 1, [ '5' ], {} ); // $ExpectError - slice( x, null, 1, ( x: number ): number => x, {} ); // $ExpectError - - slice( x, null, 1, undefined, '5' ); // $ExpectError - slice( x, null, 1, undefined, true ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ] ); // $ExpectError - slice( x, null, 1, undefined, ( x: number ): number => x ); // $ExpectError - - slice( x, null, 1, undefined, '5', {} ); // $ExpectError - slice( x, null, 1, undefined, false, {} ); // $ExpectError - slice( x, null, 1, undefined, true, {} ); // $ExpectError - slice( x, null, 1, undefined, [ '5' ], {} ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, '5' ); // $ExpectError - slice( x, s, 5 ); // $ExpectError - slice( x, s, true ); // $ExpectError - slice( x, s, false ); // $ExpectError - slice( x, s, null ); // $ExpectError - slice( x, s, [ '5' ] ); // $ExpectError - slice( x, 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 = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice( x, s, { 'strict': '5' } ); // $ExpectError - slice( x, s, { 'strict': 5 } ); // $ExpectError - slice( x, s, { 'strict': null } ); // $ExpectError - slice( x, s, { 'strict': [ '5' ] } ); // $ExpectError - slice( x, s, { 'strict': {} } ); // $ExpectError - slice( x, s, { 'strict': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - const s = new MultiSlice( null, null ); - - slice(); // $ExpectError - slice( x, s, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 1ff094c..0000000 --- a/examples/index.js +++ /dev/null @@ -1,108 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 S = require( '@stdlib/slice-ctor' ); -var E = require( '@stdlib/slice-multi' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray2array = require( '@stdlib/ndarray-to-array' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -var slice = require( './../lib' ); - -// Alias `null` to allow for more compact indexing expressions: -var _ = null; - -// Create a linear ndarray buffer: -var buf = zeroTo( 27 ); - -// Create an ndarray: -var x = array( buf, { - 'shape': [ 3, 3, 3 ] -}); - -// Get each matrix... -var s1 = E( 0, _, _ ); -var y1 = slice( x, s1 ); -// returns - -var a1 = ndarray2array( y1 ); -console.log( a1 ); -// => [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] - -var s2 = E( 1, _, _ ); -var y2 = slice( x, s2 ); -// returns - -var a2 = ndarray2array( y2 ); -console.log( a2 ); -// => [ [ 9, 10, 11 ], [ 12, 13, 14 ], [ 15, 16, 17 ] ] - -var s3 = E( 2, _, _ ); -var y3 = slice( x, s3 ); -// returns - -var a3 = ndarray2array( y3 ); -console.log( a3 ); -// => [ [ 18, 19, 20 ], [ 21, 22, 23 ], [ 24, 25, 26 ] ] - -// Reverse all elements: -var s = S( _, _, -1 ); -var s4 = E( s, s, s ); -var y4 = slice( x, s4 ); -// returns - -var a4 = ndarray2array( y4 ); -console.log( a4 ); -// => [...] - -// Get the second rows from each matrix: -var s5 = E( _, 1, _ ); -var y5 = slice( x, s5 ); -// returns - -var a5 = ndarray2array( y5 ); -console.log( a5 ); -// => [ [ 3, 4, 5 ], [ 12, 13, 14 ], [ 21, 22, 23 ] ] - -// Get the second columns from each matrix: -var s6 = E( _, _, 1 ); -var y6 = slice( x, s6 ); -// returns - -var a6 = ndarray2array( y6 ); -console.log( a6 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y7 = slice( x, _, _, 1 ); -// returns - -var a7 = ndarray2array( y7 ); -console.log( a7 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] - -// Use an alternative invocation style: -var y8 = slice( x, [ _, _, 1 ] ); -// returns - -var a8 = ndarray2array( y8 ); -console.log( a8 ); -// => [ [ 1, 4, 7 ], [ 10, 13, 16 ], [ 19, 22, 25 ] ] 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 137ed55..04a9184 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -20,7 +20,7 @@ // TypeScript Version: 4.1 -/// +/// import { 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..a9e6d7e --- /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/assert-has-own-property@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-multi@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/slice-base-args2multislice@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-slice@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";function h(h,p){var c,a,f,v,g,b,w;if(f={strict:!0},a=arguments.length,!s(h))throw new TypeError(l("1jV4f",h));if(e(arguments[a-1])){if(n(c=arguments[a-=1],"strict")){if(!i(c.strict))throw new TypeError(l("1jV2o","strict",c.strict));f.strict=c.strict}if(g=j(h),1===a&&g.length>0)throw new RangeError(l("1jVEt",g.join(","),0))}if(t(p)){if(b=p,a>2)throw new Error(l("1jV0m"))}else{if(r(p)){if(v=p,a>2)throw new Error(l("1jV0m"))}else for(v=[],w=1;w\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* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) );\n* // returns \n*\n* var y = slice( x, s );\n* // returns \n*\n* sh = y.shape;\n* // returns [ 2, 2 ]\n*\n* arr = ndarray2array( y );\n* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ]\n*/\nfunction slice( x, 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( '1jV4f', x ) );\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( '1jV2o', 'strict', options.strict ) );\n\t\t\t}\n\t\t\topts.strict = options.strict;\n\t\t}\n\t\tsh = getShape( x );\n\t\tif ( nargs === 1 && sh.length > 0 ) {\n\t\t\tthrow new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) );\n\t\t}\n\t}\n\tif ( isMultiSlice( s ) ) {\n\t\tS = s;\n\t\tif ( nargs > 2 ) {\n\t\t\tthrow new Error( format('1jV0m') );\n\t\t}\n\t} else {\n\t\tif ( isArrayLikeObject( s ) ) {\n\t\t\targs = s;\n\t\t\tif ( nargs > 2 ) {\n\t\t\t\tthrow new Error( format('1jV0m') );\n\t\t\t}\n\t\t} else {\n\t\t\targs = [];\n\t\t\tfor ( i = 1; 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( '1jVEu', String( args[ i ] ) ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn base( x, S, opts.strict, false );\n}\n\n\n// EXPORTS //\n\nexport default slice;\n"],"names":["slice","x","s","options","nargs","opts","args","sh","S","i","strict","arguments","length","isndarrayLike","TypeError","format","isPlainObject","hasOwnProp","isBoolean","getShape","RangeError","join","isMultiSlice","Error","isArrayLikeObject","push","args2multislice","err","MultiSlice","String","base"],"mappings":";;siCAsFA,SAASA,EAAOC,EAAGC,GAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAMJ,GAJAJ,EAAO,CACNK,QAAU,GAEXN,EAAQO,UAAUC,QACZC,EAAeZ,GACpB,MAAM,IAAIa,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAeL,UAAWP,EAAM,IAAQ,CAG5C,GAAKa,EADLd,EAAUQ,UADVP,GAAS,GAEiB,UAAa,CACtC,IAAMc,EAAWf,EAAQO,QACxB,MAAM,IAAII,UAAWC,EAAQ,QAAS,SAAUZ,EAAQO,SAEzDL,EAAKK,OAASP,EAAQO,MACtB,CAED,GADAH,EAAKY,EAAUlB,GACA,IAAVG,GAAeG,EAAGK,OAAS,EAC/B,MAAM,IAAIQ,WAAYL,EAAQ,QAASR,EAAGc,KAAM,KAAO,GAExD,CACD,GAAKC,EAAcpB,IAElB,GADAM,EAAIN,EACCE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,cAEnB,CACN,GAAKS,EAAmBtB,IAEvB,GADAI,EAAOJ,EACFE,EAAQ,EACZ,MAAM,IAAImB,MAAOR,EAAO,eAIzB,IADAT,EAAO,GACDG,EAAI,EAAGA,EAAIL,EAAOK,IACvBH,EAAKmB,KAAMd,UAAWF,IAGxB,IACCD,EAAIkB,EAAiBpB,EACrB,CAAC,MAAQqB,GAET,IAAMlB,EAAI,EAAGA,EAAIH,EAAKM,OAAQH,IAC7B,IACC,IAAImB,EAAYtB,EAAMG,GACtB,CAAC,MAAQkB,GACT,MAAM,IAAIb,UAAWC,EAAQ,QAASc,OAAQvB,EAAMG,KACpD,CAEF,CACD,CACD,OAAOqB,EAAM7B,EAAGO,EAAGH,EAAKK,QAAQ,EACjC"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 31b2c97..0000000 --- a/lib/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Return a read-only view of an input ndarray. -* -* @module @stdlib/ndarray-slice -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-array' ); -* var slice = require( '@stdlib/ndarray-slice' ); -* -* 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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.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 7194ece..0000000 --- a/lib/main.js +++ /dev/null @@ -1,153 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 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' ); -var getShape = require( '@stdlib/ndarray-shape' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Returns a read-only view of an input ndarray. -* -* @param {ndarray} x - input 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} 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 array dimensions -* @throws {RangeError} slice exceeds array bounds -* @returns {ndarray} ndarray view -* -* @example -* var Slice = require( '@stdlib/slice-ctor' ); -* var MultiSlice = require( '@stdlib/slice-multi' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var ndarray2array = require( '@stdlib/ndarray-to-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 ] ] -* -* var s = new MultiSlice( new Slice( null, null, -2 ), new Slice( null, null, -1 ) ); -* // returns -* -* var y = slice( x, s ); -* // returns -* -* sh = y.shape; -* // returns [ 2, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 2.0, 1.0 ] ] -*/ -function slice( x, 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( '1jV4f', x ) ); - } - if ( isPlainObject( arguments[ nargs-1 ] ) ) { - nargs -= 1; - options = arguments[ nargs ]; - if ( hasOwnProp( options, 'strict' ) ) { - if ( !isBoolean( options.strict ) ) { - throw new TypeError( format( '1jV2o', 'strict', options.strict ) ); - } - opts.strict = options.strict; - } - sh = getShape( x ); - if ( nargs === 1 && sh.length > 0 ) { - throw new RangeError( format( '1jVEt', sh.join( ',' ), 0 ) ); - } - } - if ( isMultiSlice( s ) ) { - S = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - if ( isArrayLikeObject( s ) ) { - args = s; - if ( nargs > 2 ) { - throw new Error( format('1jV0m') ); - } - } else { - args = []; - for ( i = 1; 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( '1jVEu', String( args[ i ] ) ) ); - } - } - } - } - return base( x, S, opts.strict, false ); -} - - -// EXPORTS // - -module.exports = slice; diff --git a/package.json b/package.json index 90f4bfe..28e60f9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Return a read-only view of an input ndarray.", "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,55 +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-slice": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/slice-base-args2multislice": "^0.2.2", - "@stdlib/slice-multi": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-base-zero-to": "^0.2.1", - "@stdlib/array-typed": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-base-assert-is-read-only": "^0.2.2", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-empty": "^0.3.0", - "@stdlib/ndarray-base-from-scalar": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-empty": "^0.3.0", - "@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..ebddcdd --- /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 5255238..0000000 --- a/test/test.js +++ /dev/null @@ -1,1923 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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-lines */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isReadOnly = require( '@stdlib/ndarray-base-assert-is-read-only' ); -var MultiSlice = require( '@stdlib/slice-multi' ); -var Slice = require( '@stdlib/slice-ctor' ); -var zeroTo = require( '@stdlib/array-base-zero-to' ); -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 slice = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof slice, '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 s; - var i; - - 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() { - slice( value, s ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (array)', function test( t ) { - var values; - var i; - - 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() { - slice( value, [] ); - }; - } -}); - -tape( 'the function throws an error if provided a first argument which is not an ndarray (slice arguments)', function test( t ) { - var values; - var i; - - 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() { - slice( value, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - true, - false, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - 5, - NaN, - null, - void 0, - [], - function noop() {} - ]; - x = 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() { - slice( x, 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 s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid slice argument (ndims=3)', function test( t ) { - var values; - var x; - var s; - var i; - - values = [ - '5', - NaN, - [], - function noop() {} - ]; - x = 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() { - slice( x, s, s, value ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (multislice, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (array, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, {} ); - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ] ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ] ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ] ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (slice arguments, options)', function test( t ) { - var values; - var slices; - var i; - - 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( x, s ) { - return function badValues() { - if ( s.length === 1 ) { - return slice( x, s[ 0 ], {} ); - } - if ( s.length === 2 ) { - return slice( x, s[ 0 ], s[ 1 ], {} ); - } - if ( s.length === 3 ) { - return slice( x, s[ 0 ], s[ 1 ], s[ 2 ], {} ); - } - }; - } -}); - -tape( 'the function throws an error if the number of slice dimensions does not match the number of array dimensions (no slice arguments, options)', function test( t ) { - var values; - var i; - - 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( x ) { - return function badValue() { - slice( x, {} ); - }; - } -}); - -tape( 'by default, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s ); - }; - } -}); - -tape( 'in strict mode, the function throws an error when a slice exceeds array bounds', function test( t ) { - var values; - var slices; - var s; - var i; - - 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( x, s ) { - return function badValues() { - slice( x, s, { - 'strict': true - }); - }; - } -}); - -tape( 'in non-strict mode, the function returns an empty array when a slice exceeds array bounds', function test( t ) { - var actual; - var values; - var slices; - var s; - var i; - - 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++ ) { - actual = slice( values[ i ], slices[ i ], { - 'strict': false - }); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( numel( actual.shape ), 0, 'returns expected value' ); - t.strictEqual( actual.dtype, values[ i ].dtype, 'returns expected value' ); - } - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, multislice)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, array)', function test( t ) { - var actual; - var x; - var s; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - s = []; - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, slice arguments)', function test( t ) { - var actual; - var x; - - x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - - actual = slice( x ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), x.get(), 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - t.end(); -}); - -tape( 'when provided a zero-dimensional input array, the function returns a zero-dimensional array view (non-base, offset)', function test( t ) { - var actual; - var x; - var s; - - x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - s = new MultiSlice(); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns a zero-dimensional array view (non-base)', function test( t ) { - var expected; - var actual; - var values; - var slices; - var x; - var s; - var i; - - 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' - }) - ]; - slices = [ - new MultiSlice( 0, 1 ), - new MultiSlice( 0, 1, 0 ), - new MultiSlice( 0 ), - new MultiSlice( 0, 1, 0, 1 ) - ]; - expected = [ - 1, - 2, - 0, - 5 - ]; - for ( i = 0; i < values.length; i++ ) { - x = values[ i ]; - s = slices[ i ]; - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), expected[ i ], 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'if all dimensions are reduced, the function returns 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 s; - - ord = 'row-major'; - dt = 'float64'; - buf = typedarray( zeroTo( 30 ), dt ); - - sh = [ 6 ]; - st = [ 2 ]; - o = 5; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 7, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 3, 3 ]; - st = [ 6, 2 ]; - o = 10; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 0, 1 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 12, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ 12, 6, 2 ]; - o = 3; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 25, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - sh = [ 2, 2, 3 ]; - st = [ -12, -6, -2 ]; - o = 25; - x = new ctor( dt, buf, sh, st, o, ord ); - s = new MultiSlice( 1, 1, 2 ); - - actual = slice( x, s ); - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.ndims, 0, 'returns expected value' ); - t.strictEqual( actual.get(), 3, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new MultiSlice( new Slice( null, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new MultiSlice( new Slice( 4, null, -2 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new MultiSlice( new Slice( 1, null, 3 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new MultiSlice( new Slice( 4, 1, -1 ) ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = [ new Slice( null, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = [ new Slice( 4, null, -2 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = [ new Slice( 1, null, 3 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = [ new Slice( 4, 1, -1 ) ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=1, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var o; - var x; - var s; - var i; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 6 ]; - st = [ 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = null; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 6, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 4, 6, 8, 10, 12, 14 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element: - s = new Slice( null, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 14, 10, 6 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Reverse order and skip every other element, starting from second-to-last element: - s = new Slice( 4, null, -2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 8, 4 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Skip every three elements, starting from second element: - s = new Slice( 1, null, 3 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 2, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 6, 12 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - - // Get a sub-array: - s = new Slice( 4, 1, -1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.strictEqual( actual.length, 3, 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 12, 10, 8 ]; - for ( i = 0; i < expected.length; i++ ) { - t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, multislice)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, array)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = [ null, null ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - s = [ s0, s1 ]; - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, slice arguments)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 4; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s0 = null; - s1 = null; - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - s0 = new Slice( null, null, -2 ); - s1 = new Slice( null, null, -2 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 26, 22 ], - [ 14, 10 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = new Slice( 1, null, -1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 18, 16 ], - [ 6, 4 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - s0 = new Slice( 2, 0, -1 ); - s1 = new Slice( 0, 2, 1 ); - actual = slice( x, s0, s1 ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 16, 18 ], - [ 10, 12 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=2, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 30 ), 'float64' ); - sh = [ 4, 3 ]; - st = [ 6, 2 ]; - o = 5; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 4 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 7, 13, 19, 25 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 15, 11 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip every other element, starting from second-to-last element: - s0 = new Slice( 2, null, -2 ); - s1 = 2; - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 21, 9 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a row: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s = new MultiSlice( s0, s1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 11, 13 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ 24, 6, 2 ]; - o = 10; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, null, null ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, '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: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 56, 52 ], - [ 44, 40 ] - ], - [ - [ 32, 28 ], - [ 20, 16 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements, starting from specified elements: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 24, 22 ], - [ 12, 10 ] - ], - [ - [ 48, 46 ], - [ 36, 34 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get a sub-array: - 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 = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 3, 'returns expected value' ); - t.deepEqual( actual.shape, [ 1, 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ - [ 22, 24 ], - [ 16, 18 ] - ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a view of a provided input array (ndims=3, partial reduction)', function test( t ) { - var expected; - var actual; - var buf; - var ord; - var sh; - var st; - var s0; - var s1; - var s2; - var o; - var x; - var s; - - buf = typedarray( zeroTo( 100 ), 'float64' ); - sh = [ 2, 4, 3 ]; - st = [ -24, -6, -2 ]; - o = 99; - ord = 'row-major'; - - x = new ctor( 'float64', buf, sh, st, o, ord ); - - s = new MultiSlice( null, 1, 1 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 91, 67 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = 1; - s1 = new Slice( null, null, -2 ); - s2 = new Slice( null, null, -1 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 3 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 53, 55, 57 ], - [ 65, 67, 69 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Reverse order and skip elements: - s0 = new Slice( 1, null, -1 ); - s1 = 2; - s2 = new Slice( null, null, 2 ); - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 2, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2, 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ - [ 63, 59 ], - [ 87, 83 ] - ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - - // Get part of a column: - s0 = 1; - s1 = new Slice( 0, 2, 1 ); - s2 = 2; - s = new MultiSlice( s0, s1, s2 ); - actual = slice( x, s ); - - t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.strictEqual( actual.ndims, 1, 'returns expected value' ); - t.deepEqual( actual.shape, [ 2 ], 'returns expected value' ); - t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); - t.strictEqual( actual.data, x.data, 'returns expected value' ); - - expected = [ 71, 65 ]; - actual = ndarray2array( actual ); - t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); -});